<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片 -->
    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input
            placeholder="请输入内容"
            v-model="orderInfo.query"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
            ></el-button>
          </el-input>
        </el-col>
      </el-row>

      <!-- 表格 -->
      <el-table
        :data="orderList"
        style="width: 100%"
        border
        stripe
      >
        <el-table-column type="index"></el-table-column>
        <el-table-column
          prop="order_number"
          label="订单号"
          width="380"
        >
        </el-table-column>
        <el-table-column
          prop="order_price"
          label="订单价格"
        >
        </el-table-column>
        <el-table-column
          prop="order_pay"
          label="是否付款"
        >
          <template slot-scope="scope">
            <el-tag v-if="scope.row.order_pay === '1'">已付款</el-tag>
            <el-tag
              v-else
              type="danger"
            >未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="is_send"
          label="是否发货"
        >
        </el-table-column>
        <el-table-column
          prop="update_time"
          label="下单时间"
          width="200"
        >
          <template slot-scope="scope">
            {{scope.row.update_time | dateFormat}}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
            ></el-button>
            <el-button
              type="success"
              icon="el-icon-location"
              size="mini"
              @click="locationClick"
            ></el-button>
          </template>

        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="orderInfo.pagenum"
        :page-sizes="[5, 10, 15]"
        :page-size="orderInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="orderTotal"
      >
      </el-pagination>
    </el-card>

    <!-- 物流对话框 -->
    <el-dialog
      title="物流进度"
      :visible.sync="locationDialogVisible"
      width="50%"
      :lock-scroll="false"
    >
      <el-timeline :reverse="false">
        <el-timeline-item
          v-for="(activity, index) in kuaidi"
          :key="index"
          :timestamp="activity.time"
        >
          {{activity.context}}
        </el-timeline-item>
      </el-timeline>
      <span slot="footer">
        <el-button @click="locationDialogVisible = false">取 消</el-button>
        <el-button
          type="primary"
          @click="locationDialogVisible = false"
        >确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { getData } from "network/order";
export default {
  data() {
    return {
      orderInfo: {
        query: "",
        pagenum: 1,
        pagesize: 10
      },
      orderList: [],
      orderTotal: null,
      locationDialogVisible: false,
      kuaidi: []
    };
  },
  methods: {
    getData() {
      getData("/orders", this.orderInfo).then(res => {
        // console.log(res)
        if (res.data.meta.status === 200) {
          this.orderList = res.data.data.goods;
          this.orderTotal = res.data.data.total;
          // console.log(this.orderList);
        } else {
          this.$Message.error("数据获取失败！");
        }
      });
    },
    handleSizeChange(handleSize) {
      this.orderInfo.pagesize = handleSize;
      this.getData();
    },
    handleCurrentChange(handleNum) {
      this.orderInfo.pagenum = handleNum;
      this.getData();
    },
    locationClick() {
      this.locationDialogVisible = true;
      getData("/kuaidi/1106975712662").then(res => {
        // console.log(res)
        if (res.data.meta.status === 200) {
          this.kuaidi = res.data.data;
          // console.log(this.kuaidi)
        } else {
          this.$Message.error("查询失败！");
        }
      });
    }
  },
  created() {
    this.getData();
  }
};
</script>
<style scoped>
.el-card {
  margin-top: 20px;
}
.el-row {
  margin-bottom: 15px;
}
</style>